package com.glh.javalogic.chapter5._interface;

/**
 * <pre>
 *     author : 高磊华
 *     e-mail : 984992087@qq.com
 *     time   : 2017/09/21
 *     desc   :
 * </pre>
 */


public class CompUtil {

    public static Object max(MyComparable[] objs) {
        if (objs == null || objs.length == 0) {
            return null;
        }

        MyComparable max = objs[0];
        for (int i = 0; i < objs.length; i++) {
            if (max.compareTo(objs[i]) < 0) {
                max = objs[i];
            }
        }
        return max;
    }

    public static void sort(MyComparable[] objs) {

        for (int i = 0; i < objs.length; i++) {
            for (int j = i + 1; j < objs.length; j++) {
                if (objs[i].compareTo(objs[j]) < 0) {
                    MyComparable temp = objs[i];
                    objs[i] = objs[j];
                    objs[j] = temp;

                }
            }
        }
    }

}
